import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'

import type {
  IBomProductListParams,
  IBomProductListItem,
  IAddBomProduct,
  IBomItemResult,
  IBomItemParams,
  GetBomProductTreeResult
} from './model/bomProductModel'
enum Api {
  // 产品分页查询
  GET_BOM_PRODUCT_LIST = '/footprint/bomProduct/pageProduct',
  // 删除产品
  DEL_BOM_PRODUCT = '/footprint/bomProduct/deleteProduct',
  // 新建产品
  CREATE_BOM_PRODUCT = '/footprint/bomProduct/addProduct',
  EDIT_BOM_PRODUCT = '/footprint/bomProduct/editProduct',
  GET_BOM_PRODUCT_DETAIL = '/footprint/bomProduct/getProduct',

  //供应商用户分页
  GET_ITEM_LIST = '/footprint/bomProduct/pageItem',
  // 材料树形结构
  GET_TREE_MATERIAL = '/footprint/bomProduct/treeMaterial',
  // 同步bom数据
  SYNC_PRODUCT_BOM_DATA = '/footprint/bomProduct/syncProductBomData',
  // 整合Bom树形结构
  GET_BOM_PRODUCT_TREE = '/footprint/bomProduct/treeBom',
  // 同步一级零部件下子集
  SYNC_FIRST_PART = '/footprint/bomProduct/syncFirstLevelParts'
}
// 分页查询产品数据
export const getBomProductList = (
  params: IBomProductListParams & BasicPagingListParams
): Promise<BasicPagingListResult<IBomProductListItem>> => get(Api.GET_BOM_PRODUCT_LIST, params)

export const getBomProductDetail = (productNo: string): Promise<IBomProductListItem> =>
  get(Api.GET_BOM_PRODUCT_DETAIL, { productNo })

export const delBomProduct = (productNo: string): Promise<void> =>
  post(Api.DEL_BOM_PRODUCT, { productNo })

export const createBomProduct = (params: IAddBomProduct): Promise<void> =>
  post(Api.CREATE_BOM_PRODUCT, params)

export const editBomProduct = (params: IAddBomProduct): Promise<void> =>
  post(Api.EDIT_BOM_PRODUCT, params)

export const getItemList = (
  params: IBomItemParams & BasicPagingListParams
): Promise<BasicPagingListResult<IBomItemResult>> => get(Api.GET_ITEM_LIST, params)

export const getTreeMaterial = (nodeNo: string): Promise<any> =>
  get(Api.GET_TREE_MATERIAL, { nodeNo })

export const syncBomProduct = (productNo: string): Promise<void> =>
  post(Api.SYNC_PRODUCT_BOM_DATA, { productNo })

/**
 * 整合Bom树形结构
 */
export const getBomProductTree = (
  productNo: string,
  parentNodeNo: string
): Promise<GetBomProductTreeResult[]> => get(Api.GET_BOM_PRODUCT_TREE, { productNo, parentNodeNo })
/**
 * 同步一级零部件下子集
 */
export const postSyncFirstPart = (productNo: string, nodeNo: string): Promise<void> =>
  post(Api.SYNC_FIRST_PART, { productNo, nodeNo })

// export const getSupplierUserList = (
//   params: BasicPagingListParams & { enterpriseNo: string }
// ): Promise<BasicPagingListResult<IUser>> => get(Api.GET_SUPPLIER_USER_LIST, params);
// export const delSupplierUser = (userId: string): Promise<void> =>
//   post(Api.DEL_SUPPLIER_USER, { userId });
// export const createSupplierUser = (params: ICreateUser): Promise<void> =>
//   post(Api.CREATE_SUPPLIER_USER, params);
// export const editSupplierUser = (params: IEditUser): Promise<void> =>
//   post(Api.EDIT_SUPPLIER_USER, params);
